/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-04-11
 * Time: 12:03
 */
//class Person implements Cloneable {
//    public int score = 96;
//    @Override
//    public String toString() {
//        return "Person{" +
//                "score=" + score +
//                '}';
//    }
//
//    @Override
//    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
//    }
//}
//class SmartPhone /*implements Cloneable*/{
//      public int money = 9999;
//
////    @Override
////    protected Object clone() throws CloneNotSupportedException {
////        return super.clone();
////    }
//}
//class Person implements Cloneable {
//    public int score = 96;
//    SmartPhone smartPhone = new SmartPhone();
//    @Override
//    protected Object clone() throws CloneNotSupportedException {
////        Person tmp = (Person)super.clone();
////        tmp.smartPhone =(SmartPhone) this.smartPhone.clone();
////        return tmp;
//        return super.clone();
//    }
//}

class SmartPhone{
    public int money = 9999;
}
class Person implements Cloneable {
    public int score = 96;
    SmartPhone smartPhone = new SmartPhone();
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
//深拷贝
public class TestDemo {

    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();
        Person person2 = (Person)person1.clone();
        System.out.println(person2.score);
        System.out.println(person2.smartPhone.money);
        person1.score =100;
        person1.smartPhone.money=100;
        System.out.println(person2.score);
        System.out.println(person2.smartPhone.money);
    }
}
//浅拷贝
//public class TestDemo {
//
//    public static void main(String[] args) throws CloneNotSupportedException {
//         Person person1 = new Person();
//         Person person2 = (Person)person1.clone();
//         System.out.println(person2.score);
//        System.out.println(person1.smartPhone.gameName);
//    }
//}
